<?php
/**
 * @Notes:【】
 * @User: zwc
 * @Date: 2022-05-04 13:31
 */

namespace App\Controller\Tasker\Task;

use App\Controller\User\BaseController;
use App\Dao\Task\TaskLogDao;
use App\Middleware\AuthTokenMiddleware;
use App\Service\Task\TaskLogService;
use App\Service\Task\TaskService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Middleware;
use Yj\Apidog\Annotation\ApiController;
use Yj\Apidog\Annotation\FormData;
use Yj\Apidog\Annotation\PostApi;
use Yj\FormBuilder\Annotation\Info;


/**
 * @Notes:【】
 * @User: zwc
 * @Date: 2022-05-04 13:31
 * @Middleware(AuthTokenMiddleware::class)
 * @ApiController(prefix="tasker/task")
 */
class TaskController extends BaseController
{
    /**
     * @Inject()
     * @var TaskService
     */
    protected $taskService;

    /**
     * @Notes:【列表】
     * @User: zwc
     * @Date: 2022-05-04 13:32
     * @PostApi(path="lists")
     * @FormData(key="status",rule="Required")
     */
    public function lists()
    {
        $params = $this->getData();
        $data = $this->taskService->lists($params);
        _SUCCESS($data);
    }


    /**
     * @Notes:【】
     * @Date: 2022-06-06 0:46
     * @PostApi(path="shelf")
     * @FormData(key="task_id",rule="Required")
     */
    public function shelf()
    {
        $data = $this->getData();
        $task = $this->taskService->shelf(
            $data->get('task_id')
        );
        _SUCCESS();
    }

    /**
     * @Notes:【】
     * @User: zwc
     * @Date: 2022-05-09 21:06
     * @PostApi(path="detail")
     * @FormData(key="task_id",rule="Required")
     * @FormData(key="task_receive_id",rule="Required",default="0")
     */
    public function detail()
    {
        $validator = $this->getData();
        $data = $this->taskService->detail($validator);
        _SUCCESS($data);
    }

    /**
     * @Notes:【添加】
     * @User: zwc
     * @Date: 2022-05-04 13:33
     * @PostApi(path="add")
     * @FormData(key="product_name",rule="Required")
     * @FormData(key="title",rule="Required")
     * @FormData(key="desc",rule="Required")
     * @FormData(key="notice",rule="Required")
     * @FormData(key="task_steps",rule="Required")
     * @FormData(key="info",rule="nullable")
     * @FormData(key="task_types_id",rule="Required")
     * @FormData(key="one_price",default="0.5")
     * @FormData(key="stock",default="10")
     */
    public function add()
    {
        $data = $this->getData();
        $task = $this->taskService->add($data);
        _SUCCESS($task);
    }

    /**
     * @Notes:【】
     * @User: zwc
     * @Date: 2022-05-04 13:33
     * @PostApi(path="edit")
     * @FormData(key="task_id",rule="Required")
     * @FormData(key="product_name",rule="nullable")
     * @FormData(key="title",rule="nullable")
     * @FormData(key="desc",rule="nullable")
     * @FormData(key="notice",rule="nullable")
     * @FormData(key="task_steps",rule="nullable")
     * @FormData(key="info",rule="nullable")
     * @FormData(key="type",rule="nullable")
     * @FormData(key="price",rule="nullable")
     * @FormData(key="one_price",rule="nullable")
     * @FormData(key="end_time",rule="nullable|date")
     * @FormData(key="stock",rule="nullable")
     * @FormData(key="audit_cycle",rule="nullable")
     * @FormData(key="submit_cycle",rule="nullable")
     * @FormData(key="device",rule="nullable")
     */
    public function edit()
    {
        $data = $this->getValidatorData();
        $data->offsetSet('total_stock', $data->get('stock'));
        $task = $this->taskService->edit(
            $data->get('task_id'),
            $data->except('task_id')
        );
        _SUCCESS();
    }

    /**
     * @Notes:【】
     * @Date: 2022-06-01 14:56
     * @PostApi(path="changePrice")
     * @FormData(key="one_price",rule="nullable")
     * @FormData(key="task_id",rule="Required")
     */
    public function changePrice()
    {
        $data = $this->getValidatorData();
        $task = $this->taskService->changePrice(
            $data->get('task_id'),
            $data->get('one_price')
        );
        _SUCCESS();
    }


    /**
     * @Notes:【】
     * @Date: 2022-06-01 14:56
     * @PostApi(path="changeNumber")
     * @FormData(key="stock",rule="nullable")
     * @FormData(key="task_id",rule="Required")
     */
    public function changeNumber()
    {
        $data = $this->getValidatorData();
        $task = $this->taskService->changeStock(
            $data->get('task_id'),
            $data->get('stock')
        );
        _SUCCESS();
    }

    public function pay()
    {

    }

    /**
     * @Notes:【领取任务】
     * @User: zwc
     * @Date: 2022-05-16 0:36
     * @PostApi(path="receive")
     * @FormData(key="task_id",rule="Required")
     */
    public function receive()
    {
        $data = $this->getValidatorData();
        $userId = $this->getUid();
        $task = $this->taskService->receive(
            $userId,
            $data->get('task_id')
        );
        _SUCCESS();
    }


    /**
     * @Notes:【】
     * @User: zwc
     * @Date: 2022-05-16 0:51
     * @PostApi(path="complaint")
     * @FormData(key="task_id",rule="Required")
     */
    public function complaint()
    {
        $userId = $this->getUid();
        $params = $this->getParams();
        $this->taskService->complaint($userId, $params);
        _SUCCESS();
    }

    /**
     * @Notes:【屏蔽想】
     * @User: zwc
     * @Date: 2022-05-16 0:52
     * @FormData(key="task_id",rule="Required")
     */
    public function shield()
    {

    }

    /**
     * @Notes:【】
     * @User: zwc
     * @Date: 2022-05-04 13:34
     * @PostApi(path="delete")
     */
    public function delete()
    {

    }

    /**
     * @Notes:【】
     * @Date: 2022-06-12 19:08
     * @PostApi(path="top")
     * @FormData(key="task_id",rule="Required")
     */
    public function top()
    {
        $params = $this->getParams();
        $task = $this->taskService->top(
            $this->getUid(),
            $params->get('task_id')
        );
        _SUCCESS();
    }

    /**
     * @Notes:【】
     * @Date: 2022-06-12 19:09
     * @PostApi(path="refresh")
     * @FormData(key="task_id",rule="Required")
     */
    public function refresh()
    {
        $params = $this->getParams();

        $this->taskService->refresh(
            $this->getUid(),
            $params->get('task_id')
        );
        _SUCCESS();
    }

    /**
     * @PostApi(path="settlement")
     * @FormData(key="task_id",rule="Required")
     */
    public function settlement()
    {
        $task_id = $this->getParams()->get('task_id');
        $uid = $this->getUid();
        $this->taskService->settlement($task_id, $uid);
        _SUCCESS();
    }

    /**
     * @Inject()
     * @var TaskLogService
     */
    protected $taskLogService;

    /**
     * @PostApi(path="log")
     */
    public function log()
    {
        $user_id = $this->getUid();
        $params = _Collect([]);
        $params->put('user_id', $user_id);
        $data = $this->taskLogService->lists($params);
        _SUCCESS($data);
    }

    /**
     * @PostApi(path="statistics")
     */
    public function statistics()
    {
        $user_id = $this->getUid();
        $params = $this->getParams();
        $params->put('user_id', $user_id);
        $data = $this->taskService->getStatistics($params);
        _SUCCESS($data);
    }
}